package com.room.search.web.rest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.room.search.IntegrationTest;
import com.room.search.domain.RoomGoodSearch;
import com.room.search.repository.RoomGoodSearchRepository;
import com.room.search.service.dto.RoomGoodSearchDTO;
import com.room.search.service.mapper.RoomGoodSearchMapper;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;

/**
 * Integration tests for the {@link RoomGoodSearchResource} REST controller.
 */
@IntegrationTest
@AutoConfigureMockMvc
@WithMockUser
class RoomGoodSearchResourceIT {

    private static final String DEFAULT_BK_ROOM_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_BK_ROOM_TYPE = "BBBBBBBBBB";

    private static final String DEFAULT_BK_NO = "AAAAAAAAAA";
    private static final String UPDATED_BK_NO = "BBBBBBBBBB";

    private static final String DEFAULT_TITLE = "AAAAAAAAAA";
    private static final String UPDATED_TITLE = "BBBBBBBBBB";

    private static final String DEFAULT_PRICE = "AAAAAAAAAA";
    private static final String UPDATED_PRICE = "BBBBBBBBBB";

    private static final String DEFAULT_ROOM_BASIC = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_BASIC = "BBBBBBBBBB";

    private static final String DEFAULT_ROOM_TRANSACTION = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_TRANSACTION = "BBBBBBBBBB";

    private static final String DEFAULT_RENT_BASIC = "AAAAAAAAAA";
    private static final String UPDATED_RENT_BASIC = "BBBBBBBBBB";

    private static final Long DEFAULT_COMMUNITY_ID = 1L;
    private static final Long UPDATED_COMMUNITY_ID = 2L;

    private static final String DEFAULT_ROOM_FEATURES = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_FEATURES = "BBBBBBBBBB";

    private static final String DEFAULT_ROOM_SELL_POINT = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_SELL_POINT = "BBBBBBBBBB";

    private static final String DEFAULT_COMMUNITY_INTRODUCTION = "AAAAAAAAAA";
    private static final String UPDATED_COMMUNITY_INTRODUCTION = "BBBBBBBBBB";

    private static final String DEFAULT_ROOM_INTRODUCTION = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_INTRODUCTION = "BBBBBBBBBB";

    private static final String DEFAULT_SURROUNDING_FACILITIES = "AAAAAAAAAA";
    private static final String UPDATED_SURROUNDING_FACILITIES = "BBBBBBBBBB";

    private static final String DEFAULT_TRANSPORTATION = "AAAAAAAAAA";
    private static final String UPDATED_TRANSPORTATION = "BBBBBBBBBB";

    private static final String ENTITY_API_URL = "/api/room-good-searches";
    private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";

    private static Random random = new Random();
    private static AtomicLong count = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));

    @Autowired
    private RoomGoodSearchRepository roomGoodSearchRepository;

    @Autowired
    private RoomGoodSearchMapper roomGoodSearchMapper;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restRoomGoodSearchMockMvc;

    private RoomGoodSearch roomGoodSearch;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomGoodSearch createEntity(EntityManager em) {
        RoomGoodSearch roomGoodSearch = new RoomGoodSearch()
            .bkRoomType(DEFAULT_BK_ROOM_TYPE)
            .bkNo(DEFAULT_BK_NO)
            .title(DEFAULT_TITLE)
            .price(DEFAULT_PRICE)
            .roomBasic(DEFAULT_ROOM_BASIC)
            .roomTransaction(DEFAULT_ROOM_TRANSACTION)
            .rentBasic(DEFAULT_RENT_BASIC)
            .communityId(DEFAULT_COMMUNITY_ID)
            .roomFeatures(DEFAULT_ROOM_FEATURES)
            .roomSellPoint(DEFAULT_ROOM_SELL_POINT)
            .communityIntroduction(DEFAULT_COMMUNITY_INTRODUCTION)
            .roomIntroduction(DEFAULT_ROOM_INTRODUCTION)
            .surroundingFacilities(DEFAULT_SURROUNDING_FACILITIES)
            .transportation(DEFAULT_TRANSPORTATION);
        return roomGoodSearch;
    }

    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomGoodSearch createUpdatedEntity(EntityManager em) {
        RoomGoodSearch roomGoodSearch = new RoomGoodSearch()
            .bkRoomType(UPDATED_BK_ROOM_TYPE)
            .bkNo(UPDATED_BK_NO)
            .title(UPDATED_TITLE)
            .price(UPDATED_PRICE)
            .roomBasic(UPDATED_ROOM_BASIC)
            .roomTransaction(UPDATED_ROOM_TRANSACTION)
            .rentBasic(UPDATED_RENT_BASIC)
            .communityId(UPDATED_COMMUNITY_ID)
            .roomFeatures(UPDATED_ROOM_FEATURES)
            .roomSellPoint(UPDATED_ROOM_SELL_POINT)
            .communityIntroduction(UPDATED_COMMUNITY_INTRODUCTION)
            .roomIntroduction(UPDATED_ROOM_INTRODUCTION)
            .surroundingFacilities(UPDATED_SURROUNDING_FACILITIES)
            .transportation(UPDATED_TRANSPORTATION);
        return roomGoodSearch;
    }

    @BeforeEach
    public void initTest() {
        roomGoodSearch = createEntity(em);
    }

    @Test
    @Transactional
    void createRoomGoodSearch() throws Exception {
        int databaseSizeBeforeCreate = roomGoodSearchRepository.findAll().size();
        // Create the RoomGoodSearch
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(roomGoodSearch);
        restRoomGoodSearchMockMvc
            .perform(
                post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isCreated());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeCreate + 1);
        RoomGoodSearch testRoomGoodSearch = roomGoodSearchList.get(roomGoodSearchList.size() - 1);
        assertThat(testRoomGoodSearch.getBkRoomType()).isEqualTo(DEFAULT_BK_ROOM_TYPE);
        assertThat(testRoomGoodSearch.getBkNo()).isEqualTo(DEFAULT_BK_NO);
        assertThat(testRoomGoodSearch.getTitle()).isEqualTo(DEFAULT_TITLE);
        assertThat(testRoomGoodSearch.getPrice()).isEqualTo(DEFAULT_PRICE);
        assertThat(testRoomGoodSearch.getRoomBasic()).isEqualTo(DEFAULT_ROOM_BASIC);
        assertThat(testRoomGoodSearch.getRoomTransaction()).isEqualTo(DEFAULT_ROOM_TRANSACTION);
        assertThat(testRoomGoodSearch.getRentBasic()).isEqualTo(DEFAULT_RENT_BASIC);
        assertThat(testRoomGoodSearch.getCommunityId()).isEqualTo(DEFAULT_COMMUNITY_ID);
        assertThat(testRoomGoodSearch.getRoomFeatures()).isEqualTo(DEFAULT_ROOM_FEATURES);
        assertThat(testRoomGoodSearch.getRoomSellPoint()).isEqualTo(DEFAULT_ROOM_SELL_POINT);
        assertThat(testRoomGoodSearch.getCommunityIntroduction()).isEqualTo(DEFAULT_COMMUNITY_INTRODUCTION);
        assertThat(testRoomGoodSearch.getRoomIntroduction()).isEqualTo(DEFAULT_ROOM_INTRODUCTION);
        assertThat(testRoomGoodSearch.getSurroundingFacilities()).isEqualTo(DEFAULT_SURROUNDING_FACILITIES);
        assertThat(testRoomGoodSearch.getTransportation()).isEqualTo(DEFAULT_TRANSPORTATION);
    }

    @Test
    @Transactional
    void createRoomGoodSearchWithExistingId() throws Exception {
        // Create the RoomGoodSearch with an existing ID
        roomGoodSearch.setId(1L);
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(roomGoodSearch);

        int databaseSizeBeforeCreate = roomGoodSearchRepository.findAll().size();

        // An entity with an existing ID cannot be created, so this API call must fail
        restRoomGoodSearchMockMvc
            .perform(
                post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeCreate);
    }

    @Test
    @Transactional
    void getAllRoomGoodSearches() throws Exception {
        // Initialize the database
        roomGoodSearchRepository.saveAndFlush(roomGoodSearch);

        // Get all the roomGoodSearchList
        restRoomGoodSearchMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(roomGoodSearch.getId().intValue())))
            .andExpect(jsonPath("$.[*].bkRoomType").value(hasItem(DEFAULT_BK_ROOM_TYPE)))
            .andExpect(jsonPath("$.[*].bkNo").value(hasItem(DEFAULT_BK_NO)))
            .andExpect(jsonPath("$.[*].title").value(hasItem(DEFAULT_TITLE.toString())))
            .andExpect(jsonPath("$.[*].price").value(hasItem(DEFAULT_PRICE)))
            .andExpect(jsonPath("$.[*].roomBasic").value(hasItem(DEFAULT_ROOM_BASIC.toString())))
            .andExpect(jsonPath("$.[*].roomTransaction").value(hasItem(DEFAULT_ROOM_TRANSACTION.toString())))
            .andExpect(jsonPath("$.[*].rentBasic").value(hasItem(DEFAULT_RENT_BASIC.toString())))
            .andExpect(jsonPath("$.[*].communityId").value(hasItem(DEFAULT_COMMUNITY_ID.intValue())))
            .andExpect(jsonPath("$.[*].roomFeatures").value(hasItem(DEFAULT_ROOM_FEATURES.toString())))
            .andExpect(jsonPath("$.[*].roomSellPoint").value(hasItem(DEFAULT_ROOM_SELL_POINT.toString())))
            .andExpect(jsonPath("$.[*].communityIntroduction").value(hasItem(DEFAULT_COMMUNITY_INTRODUCTION.toString())))
            .andExpect(jsonPath("$.[*].roomIntroduction").value(hasItem(DEFAULT_ROOM_INTRODUCTION.toString())))
            .andExpect(jsonPath("$.[*].surroundingFacilities").value(hasItem(DEFAULT_SURROUNDING_FACILITIES.toString())))
            .andExpect(jsonPath("$.[*].transportation").value(hasItem(DEFAULT_TRANSPORTATION.toString())));
    }

    @Test
    @Transactional
    void getRoomGoodSearch() throws Exception {
        // Initialize the database
        roomGoodSearchRepository.saveAndFlush(roomGoodSearch);

        // Get the roomGoodSearch
        restRoomGoodSearchMockMvc
            .perform(get(ENTITY_API_URL_ID, roomGoodSearch.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(roomGoodSearch.getId().intValue()))
            .andExpect(jsonPath("$.bkRoomType").value(DEFAULT_BK_ROOM_TYPE))
            .andExpect(jsonPath("$.bkNo").value(DEFAULT_BK_NO))
            .andExpect(jsonPath("$.title").value(DEFAULT_TITLE.toString()))
            .andExpect(jsonPath("$.price").value(DEFAULT_PRICE))
            .andExpect(jsonPath("$.roomBasic").value(DEFAULT_ROOM_BASIC.toString()))
            .andExpect(jsonPath("$.roomTransaction").value(DEFAULT_ROOM_TRANSACTION.toString()))
            .andExpect(jsonPath("$.rentBasic").value(DEFAULT_RENT_BASIC.toString()))
            .andExpect(jsonPath("$.communityId").value(DEFAULT_COMMUNITY_ID.intValue()))
            .andExpect(jsonPath("$.roomFeatures").value(DEFAULT_ROOM_FEATURES.toString()))
            .andExpect(jsonPath("$.roomSellPoint").value(DEFAULT_ROOM_SELL_POINT.toString()))
            .andExpect(jsonPath("$.communityIntroduction").value(DEFAULT_COMMUNITY_INTRODUCTION.toString()))
            .andExpect(jsonPath("$.roomIntroduction").value(DEFAULT_ROOM_INTRODUCTION.toString()))
            .andExpect(jsonPath("$.surroundingFacilities").value(DEFAULT_SURROUNDING_FACILITIES.toString()))
            .andExpect(jsonPath("$.transportation").value(DEFAULT_TRANSPORTATION.toString()));
    }

    @Test
    @Transactional
    void getNonExistingRoomGoodSearch() throws Exception {
        // Get the roomGoodSearch
        restRoomGoodSearchMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    void putNewRoomGoodSearch() throws Exception {
        // Initialize the database
        roomGoodSearchRepository.saveAndFlush(roomGoodSearch);

        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();

        // Update the roomGoodSearch
        RoomGoodSearch updatedRoomGoodSearch = roomGoodSearchRepository.findById(roomGoodSearch.getId()).get();
        // Disconnect from session so that the updates on updatedRoomGoodSearch are not directly saved in db
        em.detach(updatedRoomGoodSearch);
        updatedRoomGoodSearch
            .bkRoomType(UPDATED_BK_ROOM_TYPE)
            .bkNo(UPDATED_BK_NO)
            .title(UPDATED_TITLE)
            .price(UPDATED_PRICE)
            .roomBasic(UPDATED_ROOM_BASIC)
            .roomTransaction(UPDATED_ROOM_TRANSACTION)
            .rentBasic(UPDATED_RENT_BASIC)
            .communityId(UPDATED_COMMUNITY_ID)
            .roomFeatures(UPDATED_ROOM_FEATURES)
            .roomSellPoint(UPDATED_ROOM_SELL_POINT)
            .communityIntroduction(UPDATED_COMMUNITY_INTRODUCTION)
            .roomIntroduction(UPDATED_ROOM_INTRODUCTION)
            .surroundingFacilities(UPDATED_SURROUNDING_FACILITIES)
            .transportation(UPDATED_TRANSPORTATION);
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(updatedRoomGoodSearch);

        restRoomGoodSearchMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomGoodSearchDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isOk());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
        RoomGoodSearch testRoomGoodSearch = roomGoodSearchList.get(roomGoodSearchList.size() - 1);
        assertThat(testRoomGoodSearch.getBkRoomType()).isEqualTo(UPDATED_BK_ROOM_TYPE);
        assertThat(testRoomGoodSearch.getBkNo()).isEqualTo(UPDATED_BK_NO);
        assertThat(testRoomGoodSearch.getTitle()).isEqualTo(UPDATED_TITLE);
        assertThat(testRoomGoodSearch.getPrice()).isEqualTo(UPDATED_PRICE);
        assertThat(testRoomGoodSearch.getRoomBasic()).isEqualTo(UPDATED_ROOM_BASIC);
        assertThat(testRoomGoodSearch.getRoomTransaction()).isEqualTo(UPDATED_ROOM_TRANSACTION);
        assertThat(testRoomGoodSearch.getRentBasic()).isEqualTo(UPDATED_RENT_BASIC);
        assertThat(testRoomGoodSearch.getCommunityId()).isEqualTo(UPDATED_COMMUNITY_ID);
        assertThat(testRoomGoodSearch.getRoomFeatures()).isEqualTo(UPDATED_ROOM_FEATURES);
        assertThat(testRoomGoodSearch.getRoomSellPoint()).isEqualTo(UPDATED_ROOM_SELL_POINT);
        assertThat(testRoomGoodSearch.getCommunityIntroduction()).isEqualTo(UPDATED_COMMUNITY_INTRODUCTION);
        assertThat(testRoomGoodSearch.getRoomIntroduction()).isEqualTo(UPDATED_ROOM_INTRODUCTION);
        assertThat(testRoomGoodSearch.getSurroundingFacilities()).isEqualTo(UPDATED_SURROUNDING_FACILITIES);
        assertThat(testRoomGoodSearch.getTransportation()).isEqualTo(UPDATED_TRANSPORTATION);
    }

    @Test
    @Transactional
    void putNonExistingRoomGoodSearch() throws Exception {
        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();
        roomGoodSearch.setId(count.incrementAndGet());

        // Create the RoomGoodSearch
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(roomGoodSearch);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomGoodSearchMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomGoodSearchDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithIdMismatchRoomGoodSearch() throws Exception {
        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();
        roomGoodSearch.setId(count.incrementAndGet());

        // Create the RoomGoodSearch
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(roomGoodSearch);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomGoodSearchMockMvc
            .perform(
                put(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithMissingIdPathParamRoomGoodSearch() throws Exception {
        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();
        roomGoodSearch.setId(count.incrementAndGet());

        // Create the RoomGoodSearch
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(roomGoodSearch);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomGoodSearchMockMvc
            .perform(
                put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void partialUpdateRoomGoodSearchWithPatch() throws Exception {
        // Initialize the database
        roomGoodSearchRepository.saveAndFlush(roomGoodSearch);

        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();

        // Update the roomGoodSearch using partial update
        RoomGoodSearch partialUpdatedRoomGoodSearch = new RoomGoodSearch();
        partialUpdatedRoomGoodSearch.setId(roomGoodSearch.getId());

        partialUpdatedRoomGoodSearch
            .bkRoomType(UPDATED_BK_ROOM_TYPE)
            .bkNo(UPDATED_BK_NO)
            .roomFeatures(UPDATED_ROOM_FEATURES)
            .roomSellPoint(UPDATED_ROOM_SELL_POINT)
            .communityIntroduction(UPDATED_COMMUNITY_INTRODUCTION);

        restRoomGoodSearchMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomGoodSearch.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomGoodSearch))
            )
            .andExpect(status().isOk());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
        RoomGoodSearch testRoomGoodSearch = roomGoodSearchList.get(roomGoodSearchList.size() - 1);
        assertThat(testRoomGoodSearch.getBkRoomType()).isEqualTo(UPDATED_BK_ROOM_TYPE);
        assertThat(testRoomGoodSearch.getBkNo()).isEqualTo(UPDATED_BK_NO);
        assertThat(testRoomGoodSearch.getTitle()).isEqualTo(DEFAULT_TITLE);
        assertThat(testRoomGoodSearch.getPrice()).isEqualTo(DEFAULT_PRICE);
        assertThat(testRoomGoodSearch.getRoomBasic()).isEqualTo(DEFAULT_ROOM_BASIC);
        assertThat(testRoomGoodSearch.getRoomTransaction()).isEqualTo(DEFAULT_ROOM_TRANSACTION);
        assertThat(testRoomGoodSearch.getRentBasic()).isEqualTo(DEFAULT_RENT_BASIC);
        assertThat(testRoomGoodSearch.getCommunityId()).isEqualTo(DEFAULT_COMMUNITY_ID);
        assertThat(testRoomGoodSearch.getRoomFeatures()).isEqualTo(UPDATED_ROOM_FEATURES);
        assertThat(testRoomGoodSearch.getRoomSellPoint()).isEqualTo(UPDATED_ROOM_SELL_POINT);
        assertThat(testRoomGoodSearch.getCommunityIntroduction()).isEqualTo(UPDATED_COMMUNITY_INTRODUCTION);
        assertThat(testRoomGoodSearch.getRoomIntroduction()).isEqualTo(DEFAULT_ROOM_INTRODUCTION);
        assertThat(testRoomGoodSearch.getSurroundingFacilities()).isEqualTo(DEFAULT_SURROUNDING_FACILITIES);
        assertThat(testRoomGoodSearch.getTransportation()).isEqualTo(DEFAULT_TRANSPORTATION);
    }

    @Test
    @Transactional
    void fullUpdateRoomGoodSearchWithPatch() throws Exception {
        // Initialize the database
        roomGoodSearchRepository.saveAndFlush(roomGoodSearch);

        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();

        // Update the roomGoodSearch using partial update
        RoomGoodSearch partialUpdatedRoomGoodSearch = new RoomGoodSearch();
        partialUpdatedRoomGoodSearch.setId(roomGoodSearch.getId());

        partialUpdatedRoomGoodSearch
            .bkRoomType(UPDATED_BK_ROOM_TYPE)
            .bkNo(UPDATED_BK_NO)
            .title(UPDATED_TITLE)
            .price(UPDATED_PRICE)
            .roomBasic(UPDATED_ROOM_BASIC)
            .roomTransaction(UPDATED_ROOM_TRANSACTION)
            .rentBasic(UPDATED_RENT_BASIC)
            .communityId(UPDATED_COMMUNITY_ID)
            .roomFeatures(UPDATED_ROOM_FEATURES)
            .roomSellPoint(UPDATED_ROOM_SELL_POINT)
            .communityIntroduction(UPDATED_COMMUNITY_INTRODUCTION)
            .roomIntroduction(UPDATED_ROOM_INTRODUCTION)
            .surroundingFacilities(UPDATED_SURROUNDING_FACILITIES)
            .transportation(UPDATED_TRANSPORTATION);

        restRoomGoodSearchMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomGoodSearch.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomGoodSearch))
            )
            .andExpect(status().isOk());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
        RoomGoodSearch testRoomGoodSearch = roomGoodSearchList.get(roomGoodSearchList.size() - 1);
        assertThat(testRoomGoodSearch.getBkRoomType()).isEqualTo(UPDATED_BK_ROOM_TYPE);
        assertThat(testRoomGoodSearch.getBkNo()).isEqualTo(UPDATED_BK_NO);
        assertThat(testRoomGoodSearch.getTitle()).isEqualTo(UPDATED_TITLE);
        assertThat(testRoomGoodSearch.getPrice()).isEqualTo(UPDATED_PRICE);
        assertThat(testRoomGoodSearch.getRoomBasic()).isEqualTo(UPDATED_ROOM_BASIC);
        assertThat(testRoomGoodSearch.getRoomTransaction()).isEqualTo(UPDATED_ROOM_TRANSACTION);
        assertThat(testRoomGoodSearch.getRentBasic()).isEqualTo(UPDATED_RENT_BASIC);
        assertThat(testRoomGoodSearch.getCommunityId()).isEqualTo(UPDATED_COMMUNITY_ID);
        assertThat(testRoomGoodSearch.getRoomFeatures()).isEqualTo(UPDATED_ROOM_FEATURES);
        assertThat(testRoomGoodSearch.getRoomSellPoint()).isEqualTo(UPDATED_ROOM_SELL_POINT);
        assertThat(testRoomGoodSearch.getCommunityIntroduction()).isEqualTo(UPDATED_COMMUNITY_INTRODUCTION);
        assertThat(testRoomGoodSearch.getRoomIntroduction()).isEqualTo(UPDATED_ROOM_INTRODUCTION);
        assertThat(testRoomGoodSearch.getSurroundingFacilities()).isEqualTo(UPDATED_SURROUNDING_FACILITIES);
        assertThat(testRoomGoodSearch.getTransportation()).isEqualTo(UPDATED_TRANSPORTATION);
    }

    @Test
    @Transactional
    void patchNonExistingRoomGoodSearch() throws Exception {
        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();
        roomGoodSearch.setId(count.incrementAndGet());

        // Create the RoomGoodSearch
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(roomGoodSearch);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomGoodSearchMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, roomGoodSearchDTO.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithIdMismatchRoomGoodSearch() throws Exception {
        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();
        roomGoodSearch.setId(count.incrementAndGet());

        // Create the RoomGoodSearch
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(roomGoodSearch);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomGoodSearchMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithMissingIdPathParamRoomGoodSearch() throws Exception {
        int databaseSizeBeforeUpdate = roomGoodSearchRepository.findAll().size();
        roomGoodSearch.setId(count.incrementAndGet());

        // Create the RoomGoodSearch
        RoomGoodSearchDTO roomGoodSearchDTO = roomGoodSearchMapper.toDto(roomGoodSearch);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomGoodSearchMockMvc
            .perform(
                patch(ENTITY_API_URL)
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomGoodSearchDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomGoodSearch in the database
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void deleteRoomGoodSearch() throws Exception {
        // Initialize the database
        roomGoodSearchRepository.saveAndFlush(roomGoodSearch);

        int databaseSizeBeforeDelete = roomGoodSearchRepository.findAll().size();

        // Delete the roomGoodSearch
        restRoomGoodSearchMockMvc
            .perform(delete(ENTITY_API_URL_ID, roomGoodSearch.getId()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<RoomGoodSearch> roomGoodSearchList = roomGoodSearchRepository.findAll();
        assertThat(roomGoodSearchList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
